package me.zhengjie.modules.system.service.mapstruct.convertor.impl;

import lombok.RequiredArgsConstructor;
import me.zhengjie.config.MappingProperties;
import me.zhengjie.exception.BadRequestException;
import org.mapstruct.Named;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * SafeRiskItemConvertor
 *
 * @author guoyuan
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
@RequiredArgsConstructor
@Named("safeRiskItemConvertor")
public class SafeRiskItemConvertor {

    private final MappingProperties mappingProperties;

    @Named("sceneType2Value")
    public String sceneType2Value(String sceneType) {
        final List<String> sceneTypeList = mappingProperties.getSceneType();
        return sceneTypeList.get(Integer.parseInt(sceneType));
    }

    @Named("sceneType2Code")
    public String sceneType2Code(String sceneType) {
        final List<String> sceneTypeList = mappingProperties.getSceneType();
        final int indexOf = sceneTypeList.indexOf(sceneType);
        if (indexOf == -1) {
            throw new BadRequestException("场景类型[" + sceneType + "]不存在");
        }
        return String.valueOf(indexOf);
    }

}
